<template>
  <el-card shadow="hover" class="project-card">
    <img :src="project.thumbnail" class="project-thumbnail" />
    <div class="project-content">
      <h2 class="project-title">{{ project.title }}</h2>

      <el-tooltip
        v-bind="{
          content: project.description,
          placement: 'top',
          showAfter: 200,
          transition: 'el-fade-in-linear'
        }"
      >
        <p class="project-description">{{ project.description }}</p>
      </el-tooltip>
      <el-tag type="info" class="project-category">{{ project.category }}</el-tag>
      <div class="project-tags">
        <el-tag v-for="tag in project.tags" :key="tag" type="success" class="project-tag">{{
          tag
        }}</el-tag>
      </div>
      <el-button type="primary" plain @click="goToProject(project.projectLink)"
        >View Project</el-button
      >
      <p class="project-updated">Updated: {{ formattedUpdatedAt }}</p>
    </div>
  </el-card>
</template>

<script setup lang="ts">
import { defineProps, computed } from 'vue'
import { formatTimeAgo } from '@/utils/timeUtils'
import type { IProject } from '@/mock/mockdata'

const props = defineProps<{
  project: IProject
}>()

const { project } = props

const formattedUpdatedAt = computed(() => formatTimeAgo(project.updatedAt))

const goToProject = (link: string) => {
  window.open(link, '_blank')
}
</script>

<style scoped>
.project-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 100%;
}

.project-thumbnail {
  width: 100%;
  height: 150px;
  object-fit: cover;
  border-radius: 4px;
  margin-bottom: 10px;
}

.project-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  flex-grow: 1;
}

.project-title {
  font-size: 1.2em;
  font-weight: bold;
  margin: 10px 0;
  height: 1.2em;
  line-height: 1.2em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.project-description {
  margin: 10px 0;
  height: 2.4em; /* 1.2em line-height * 2 = 2.4em for two lines */
  line-height: 1.2em;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2; /* Limit to 2 lines */
  -webkit-box-orient: vertical;
  cursor: pointer;
}

.project-category {
  margin: 10px 0;
}

.project-tags {
  margin-bottom: 10px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
}

.project-tag {
  margin: 2px;
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-updated {
  margin-top: 10px;
  color: #999;
  font-size: 0.9em;
}

.el-tooltip__popper {
  opacity: 0.6;
  animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 0.6; /* 与 .el-tooltip__popper 保持一致 */
    transform: translateY(0);
  }
}
</style>
